package com.jt.www.enums.endorse;

import com.jt.www.util.JsonUtil;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.List;


public enum PolicyTypeEnum {
    TRAINEE_SCH("实责险（学校）", 1, "sxszrxtb", "19PR789827", "ins-sz-xx", ""),
    TRAINEE_ENT("实责险（企业）", 0, "sxszrxtb_qy", "19PR789827", "ins-sz-qy", ""),
    //STUDENT_SCH("校责险（学校）", 2, "xfzrbxtb", "19PR961660",""),
    STUDENT_SCH("校责险（学校）", 2, "xfzrbxtb_0726", "19PR961660", "ins-xz-xx", ""),
    TRAINEE_SCH_PD("实责险（学校）-批单", 3, "sxszrxtb_pd", "19PR789827","ins-sz-xx",""),
    XZ("学生安全责任保险", 7, "xsaqzrbxtb", "19PR403423", "ins-xs-aq", ""),
    YN_JZG("云南教职工校方责任保险", 4, "ynsjzg", "19PR467834", "ins-yn-jz", ""),
    YN_XF("云南校方责任保险", 10, "ynsxfzrxtb", "19PR534934", "ins-yn-xz", ""),
    YN_SP("云南省校园食品安全责任险", 11, null, "19PR233356", "ins-yn-sp", ""),
    YN_ZH("云南校方综合保障责任险", 13, "ynsxfzhbzzrbxtb", "19PR452292", "ins-yn-zh", ""),
    SD_XF("山东校（园）方责任保险", 16, "sdsxfzrbxtb", "19PR372456", "ins-sd", "FIVE_PERCENT"),
    SD_XF_OLD("山东校（园）方责任保险", 16_1, "sdsxfzrbxtb_old", "19PR372456", "ins-sd", "FIVE_PERCENT"),
    SP_XZ("校园食品安全责任保险", 17, "xyspaqzrbxtbxsqd", "19PR701524", "ins-sp", ""),
    SD_LY("山东省校（园）方责任保险-临沂市专属产品", 18, "sdsxfzrbxtb", "19PR324941", "ins-sd-linyi", "FIVE_PERCENT"),
    SX_XZ("山西校责", 19, "sxszxxyeyxfzrbxtbqd", "19PR596839", "ins-xz-sx", ""),
    SD_ZZ("山东省校（园）方责任保险-枣庄市专属产品", 20, "sdsxfzrbxtb", "19PR868691", "ins-sd-zaozhuang", "FIVE_PERCENT"),
    SD_RZ("山东省校（园）方责任保险-日照市专属产品", 21, "sdsxfzrbxtb", "19PR285352", "ins-sd-rizhao", "FIVE_PERCENT"),
    SD_WH("山东省校（园）方责任保险-威海市专属产品", 22, "sdsxfzrbxtb", "19PR352719", "ins-sd-weihai", "FIVE_PERCENT"),
    SD_TA("山东省校（园）方责任保险-泰安市专属产品", 23, "sdsxfzrbxtb", "19PR478694", "ins-sd-taian", ""),
    SD_YT("山东省校（园）方责任保险-烟台市专属产品", 24, "sdsxfzrbxtb", "19PR276530", "ins-sd-yantai", "FIVE_PERCENT"),
    SD_BZ("山东省校（园）方责任保险-滨州市专属产品", 25, "sdsxfzrbxtb", "19PR678749", "ins-sd-binzhou", ""),
    SD_JN("山东省校（园）方责任保险-济宁市专属产品", 26, "sdsxfzrbxtb", "19PR883658", "ins-sd-jining", ""),
    SD_LC("山东省校（园）方责任保险-聊城市专属产品", 27, "sdsxfzrbxtb", "19PR801279", "ins-sd-liaocheng", ""),
    SD_JINAN("山东省校（园）方责任保险-济南市专属产品", 28, "sdsxfzrbxtb", "19PR394185", "ins-sd-jinan", ""),
    GD_XZ("广东省校(园)方责任保险", 29, "", "20PR806488", "ins-gd-xz", ""),
    GD_SP("广东省校园食品安全责任保险", 30, "", "20PR191668", "ins-gd-sp", ""),
    GD_XC("广东省校车道路客运承运人责任保险", 31, "", "20PR485549", "ins-gd-xc", ""),
    GD_JZG("广东省教职员工校（园）方责任保险", 32, "gdjzg", "20PR530654", "ins-gd-jzg", ""),
    HN_SZX("湖南省职业院校学生实习责任保险", 33, "hnszx", "20PR876111", "ins-hn-sz", ""),
    HN_XZX("湖南省校方责任保险 ", 34, "hnxzx", "20PR676863", "ins-hn-xz", "");


    private String msg;
    private int code;
    private String modelCode;
    private String productCode;
    private String htmlTemplate;
    private String preferentialWay;//优惠方式

    PolicyTypeEnum(String msg, int code, String modelCode, String productCode, String htmlTemplate, String preferentialWay) {
        this.code = code;
        this.msg = msg;
        this.modelCode = modelCode;
        this.productCode = productCode;
        this.htmlTemplate = htmlTemplate;
        this.preferentialWay = preferentialWay;
    }

    public static PolicyTypeEnum getByCode(int code) {
        for (PolicyTypeEnum policyTypeEnum : PolicyTypeEnum.values()) {
            if (policyTypeEnum.code == code) {
                return policyTypeEnum;
            }
        }
        return null;
    }

    public static PolicyTypeEnum getByProductCode(String productCode) {
        for (PolicyTypeEnum policyTypeEnum : PolicyTypeEnum.values()) {
            if (policyTypeEnum.productCode.equals(productCode)) {
                return policyTypeEnum;
            }
        }
        return null;
    }

    public static PolicyTypeEnum getHtmlTemplateByProductCode(String productCode, String code) {
        if (StringUtils.isNotBlank(code)) {
            for (PolicyTypeEnum policyTypeEnum : PolicyTypeEnum.values()) {
                if (policyTypeEnum.productCode.equals(productCode) && policyTypeEnum.code == Integer.valueOf(code)) {
                    return policyTypeEnum;
                }
            }
        } else {
            for (PolicyTypeEnum policyTypeEnum : PolicyTypeEnum.values()) {
                if (policyTypeEnum.productCode.equals(productCode)) {
                    return policyTypeEnum;
                }
            }
        }
        return null;
    }

    public static String getProductCodeByPreferentialWay(String preferentialWay) {

        List<String> productCodes = new ArrayList<>();
        for (PolicyTypeEnum policyTypeEnum : PolicyTypeEnum.values()) {
            if (policyTypeEnum.preferentialWay.equals(preferentialWay)) {
                productCodes.add(policyTypeEnum.productCode);
            }
        }

        return JsonUtil.object2Json(productCodes);
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getModelCode() {
        return modelCode;
    }

    public void setModelCode(String modelCode) {
        this.modelCode = modelCode;
    }

    public String getProductCode() {
        return productCode;
    }

    public void setProductCode(String productCode) {
        this.productCode = productCode;
    }

    public String getHtmlTemplate() {
        return htmlTemplate;
    }

    public void setHtmlTemplate(String htmlTemplate) {
        this.htmlTemplate = htmlTemplate;
    }

    public String getPreferentialWay() {
        return preferentialWay;
    }

    public void setPreferentialWay(String preferentialWay) {
        this.preferentialWay = preferentialWay;
    }
}
